package team.seekers.hula.course.structure.section.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.course.structure.section.entity.dto.SectionDTO;
import team.seekers.hula.course.structure.section.entity.vo.SectionBasicListVO;
import team.seekers.hula.course.structure.section.service.SectionManageService;

import java.util.List;

/**
 * date: 2022/5/11 10:50
 *
 * @author GH
 * QQ 1124813753
 */
@Controller
@ApiResponseBody
@RequestMapping("/manage/section")
public class SectionManageController {

    @Autowired
    private SectionManageService sectionManageService;

    @GetMapping("/basic-list-by-courseId")
    public List<SectionBasicListVO> getBasicVOListByCourseId(@RequestParam String courseId) {
        return sectionManageService.getBasicVOListByCourseId(courseId);
    }

    /**
     * 新增章节并级联更新对应某章的章节集合顺序
     * @param sectionDTO 需要新增的章节
     */
    @PostMapping("/save")
    public void save(@RequestBody SectionDTO sectionDTO) {
        sectionManageService.save(sectionDTO);
    }

    /**
     * @param sectionDTO 需要更新的章节（字段值不为空则更新）
     */
    @PutMapping("/update")
    public void update(@RequestBody SectionDTO sectionDTO) {
        sectionManageService.update(sectionDTO);
    }

    /**
     * 删除章节并级联更新对应某章的章节集合顺序
     * @param sectionId 要删除的章节id
     * @param chapterId 级联更新的章id
     * @param sections 更新后的章节id集合（集合元素按第几章内章节的顺序）
     */
//    @DeleteMapping("/delete/{sectionId}")
//    public void delete(@PathVariable Long sectionId,
//                       @RequestParam Long chapterId,
//                       @RequestBody List<Long> sections) {
//        ChapterManageDTO chapterManageDTO = ChapterManageDTO.builder()
//                .id(chapterId).sections(sections).build();
//        sectionManageService.delete(sectionId, chapterManageDTO);
//    }
}
